﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FaceRecognition.Models;
using FaceRecognition.Utilities;

namespace FaceRecognition.View
{
    public partial class Form_UpdateUser : Form
    {
        User_Manager db;
        Controller_Class control;
      
        public Form_UpdateUser()
        {
            db = new User_Manager();
            control = new Controller_Class();
            InitializeComponent();
        }

     /*   private void button1_Click(object sender, EventArgs e)
        {
            string Phone;
            if(phone.Text=="")
             Phone="";
            else
            Phone=phone.Text;
            if(control.ID_Exist(Convert.ToInt32(ID.Text)))
            control.update_user_info(Convert.ToInt32(ID.Text), Fname.Text, Lname.Text, Phone, email.Text);
           

        }*/

        private void button2_Click(object sender, EventArgs e)
        {
     

            if (!General_Usage.isEmail(E_mail_search.Text))
            {
                MessageBox.Show("This email is not valid ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                if (control.User.email_exist( E_mail_search.Text))
                {
                    
                    control.User.update_user_info_by_email(Fname.Text, Lname.Text, phone.Text, email.Text, E_mail_search.Text);

                    MessageBox.Show("Succefully updated ", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                    MessageBox.Show("This email doesn't exist ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            catch
            {
                MessageBox.Show("We couldn't connect to the database ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

        }
        
    }
}
